@using ZR.CodeGenerator
@using ZR.Model.System.Generate
@using ZR.Model.System.Model.Enums;
@using Infrastructure.Extensions;
@* @model ZR.CodeGenerator.Model.GenerateDto; *@
@{
    var genOptions = Model.GenOptions;
    var genTable = Model.GenTable;
    var genTableOptions=genTable.Options;
    List<GenTableColumn> formCols = genTable.FormColumns;
    List<GenTableColumn> listCols = genTable.ListItemColumns;
    var subTableOptions = Model.SubTableOptions;
    
    var replaceDto = Model.ReplaceDto;
    var dictHtml = new string[] { GenConstants.HTML_CHECKBOX, GenConstants.HTML_RADIO,GenConstants.HTML_RADIO_BTN, GenConstants.HTML_SELECT, GenConstants.HTML_SELECT_MULTI };
    var dicts = new List<GenTableColumn>();
    dicts.AddRange(Model.GenTable.Columns.FindAll((Predicate<GenTableColumn>)(f => dictHtml.Contains(f.HtmlType))));
    if (Model.GenTable.SubTable != null && Model.GenTable.SubTableName.IsNotEmpty())
    {
        dicts.AddRange(Model.GenTable?.SubTable?.Columns?.FindAll((Predicate<GenTableColumn>)(f => dictHtml.Contains(f.HtmlType))));
    }
}
using @(genOptions.ModelsNamespace).Enums;
@if (null != genTable.SubTableName && "" != genTable.SubTableName)
{
@:using @(subTableOptions.ModelsNamespace).@(subTableOptions.SubNamespace);
}

namespace @(genOptions.DtosNamespace).@(genOptions.SubNamespace).Dto
{
    /// <summary>
    /// @(genTable.FunctionName)表单对象
    /// </summary>
    public class @(genTable.FunctionCode)FormDtoBase
    {      
@foreach (var item in formCols)
{
    var labelName = "";
    if (item.FieldDesc != "")
    {
        labelName = item.FieldDesc;
    }
    else
    {
        labelName = item.CsharpField;
    }
        @:/// <summary>
        @:/// @(labelName)
        @:/// </summary>
    if (item.IsRequired == true)
    {
        @:[Required(ErrorMessage = "@(item.FieldDesc)不能为空")]
    }
    if (replaceDto.ShowBtnExport)
    {
        if (item.IsExport)
        {
        @:[ExcelColumn(Name = "@labelName"@(item.CsharpType == "DateTime" ? ", Format = \"yyyy-MM-dd HH:mm:ss\", Width = 20" : ""))]
        @:[ExcelColumnName("@labelName")]
        }
        else
        {
        @:[ExcelIgnore]
        }
    }
        @:public @item.CsharpType@item.RequiredStr @item.CsharpField { get; set; }
        @:
}

    }

@if (replaceDto.ShowBtnDelete || replaceDto.ShowBtnMultiDel)
{
    @:/// <summary>
    @:/// 删除@(genTable.FunctionName)请求对象
    @:/// </summary>
    @:public class Delete@(genTable.FunctionCode)ReqBase
    @:{
        @:/// <summary>
        @:/// 标识集合
        @:/// </summary>
        @:public string Ids { get; set; }
    @:}
}

@if (genTableOptions.IsEnableStateChange)
{
    @:/// <summary>
    @:/// 变更@(genTable.FunctionName)状态请求对象
    @:/// </summary>
    @:public class Change@(genTable.FunctionCode)StateReqBase
    @:{
        @:/// <summary>
        @:/// 标识
        @:/// </summary>
        @:public long Id { get; set; }
        @:

        @:/// <summary>
        @:/// 状态编码
        @:/// </summary>
        @:public string StateCode { get; set; }
        @:

        @:/// <summary>
        @:/// 状态枚举
        @:/// </summary>
        @:[JsonIgnore]
        @:public DataStateEnum? StateEnum
        @:{
            @:get
            @:{
                @:DataStateEnum stateEnum;
                @:var isOk = Enum.TryParse(StateCode, true, out stateEnum);
                @:if (isOk && Enum.IsDefined(stateEnum))
                @:{
                    @:return stateEnum;
                @:}
                @:return null;
            @:}
        @:}
    @:}
}

@if(genTableOptions.IsTreeTable)
{
    @:/// <summary>
    @:/// 获取@(genTable.FunctionName)树选择列表请求对象
    @:/// </summary>
    @:public class Get@(genTable.FunctionCode)TreeSelectListReqBase:GetTreeSelectListReqBase
    @:{

    @:}
}

    /// <summary>
    /// 获取@(genTable.FunctionName)分页列表请求对象
    /// </summary>
    public class Get@(genTable.FunctionCode)PageListReqBase : PagerInfo 
    {
        @if(genTableOptions.IsShowLeftTree)
        {
        @:/// <summary>
        @:/// 树结点标识
        @:/// </summary>
        @:public long? TreeNodeId { get; set; }

        @:/// <summary>
        @:/// 是否是默认结点类型
        @:/// </summary>
        @:public bool IsDefaultNodeType { get; set; }=true;
        }

        /// <summary>
        /// 关键词
        /// </summary>
        public string Keywords { get; set; }

@foreach (var item in genTable.Columns)
{
    var labelName = "";
    if (item.FieldDesc != "")
    {
        labelName = item.FieldDesc;
    }
    else
    {
        labelName = item.CsharpField;
    }
    if (item.IsQuery)
    {
        if (item.HtmlType.StartsWith("date"))
        {
        @:/// <summary>
        @:/// 起始@(labelName)
        @:/// </summary>
        @:public DateTime? Begin@(item.CsharpField){get; set; }

        @:/// <summary>
        @:/// 终止@(labelName)
        @:/// </summary>
        @:public DateTime? End@(item.CsharpField){get; set; }
        }
        else if (item.HtmlType == "selectMulti")
        {
        @:/// <summary>
        @:/// @(labelName)
        @:/// </summary>
        @:public @(item.CsharpType)[] @item.CsharpField { get; set; }
        }
        else
        {
        @:/// <summary>
        @:/// @(labelName)
        @:/// </summary>
        @:public @item.CsharpType@(item.CsharpType != "string" ? "?" : "") @item.CsharpField { get; set; }
        }
@:
    }
}

    }

    /// <summary>
    /// @(genTable.FunctionName)列表项
    /// </summary>
    public class @(genTable.FunctionCode)ListItemDtoBase
    {
@foreach (var item in listCols)
{
    var labelName = "";
    if (item.FieldDesc != "")
    {
        labelName = item.FieldDesc;
    }
    else
    {
        labelName = item.CsharpField;
    }
    if (replaceDto.ShowBtnExport)
    {
        if (item.IsExport)
        {
        @:[ExcelColumn(Name = "@labelName"@(item.CsharpType == "DateTime" ? ", Format = \"yyyy-MM-dd HH:mm:ss\", Width = 20" : ""))]
        @:[ExcelColumnName("@labelName")]
        }
        else
        {
        @:[ExcelIgnore]
        }
    }
        @:/// <summary>
        @:/// @(labelName)
        @:/// </summary>
        @:public @item.CsharpType@item.RequiredStr @item.CsharpField { get; set; }
        @:

        if(genTableOptions.IsTreeTable && genTableOptions.TreeTableNodePaIdField==item.CsharpField)
        {
        @:public string Pa@(genTableOptions.TreeTableNodeNameField) { get; set; }
        }

        if(genTableOptions.IsShowLeftTree && item.CsharpField==genTableOptions.LeftTreeNodeIdField)
        {
        @:public string Belong@(genTableOptions.LeftTreeNodeNameField) { get; set; }
        }
}
    }

    /// <summary>
    /// @(genTable.FunctionName)详情
    /// </summary>
    public class @(genTable.FunctionCode)DetailDtoBase: @(genTable.FunctionCode)FormDto
    {

    }
}